package com.mingqi.enetconnected.primary.mytask.taskDetails;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mingqi.enetconnected.R;
import com.mingqi.enetconnected.base.BaseFragment;
import com.mingqi.enetconnected.primary.mytask.adapter.NewAddTroubleAdapter;
import com.mingqi.enetconnected.primary.mytask.adapter.SafetyTroubleAdapter;
import com.mingqi.enetconnected.primary.mytask.event.SafetyTroubleEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by li on 2018/8/13.
 * WeChat 18571658038
 * author LiWei
 */

public class SafetyTroubleFragment extends BaseFragment {


    @BindView(R.id.rv_expand_list)
    RecyclerView mRvExpandList;
    private SafetyTroubleAdapter mSafetyTroubleAdapter;

    @Override
    protected View bindView(ViewGroup container) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.fragment_safety_trouble, container, false);
        return view;
    }

    @Override
    protected void initView() {

        List<String> list = new ArrayList<>();

        list.add("新增隐患");
        list.add("历史隐患");
        mSafetyTroubleAdapter = new SafetyTroubleAdapter(mContext,list);

        mRvExpandList.setAdapter(mSafetyTroubleAdapter);
        mRvExpandList.setLayoutManager(new LinearLayoutManager(mContext));
//        mRvExpandList.addItemDecoration(new HorizontalDividerItemDecoration.Builder(mContext)
//                .colorResId(R.color.space)
//                .size(DeviceUtils.dp2px(mContext,10))
//                .build());


    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void setSafetyTrouble(SafetyTroubleEvent event){

        int type = event.getType();
        switch (type) {
            case SafetyTroubleEvent.TYPE_ADD :

                RecyclerView rvExpand = (RecyclerView) mSafetyTroubleAdapter.getViewByPosition(mRvExpandList, 0, R.id.rv_expand);
                NewAddTroubleAdapter addTroubleAdapter = (NewAddTroubleAdapter) rvExpand.getAdapter();

                addTroubleAdapter.addData(0,"");

                int visibility = rvExpand.getVisibility();
                if(visibility == View.GONE) {

                    rvExpand.setVisibility(View.VISIBLE);
                }

                break;
            case SafetyTroubleEvent.TYPE_DELETE :

                break;
            case SafetyTroubleEvent.TYPE_CHANGE :

                break;
            default:
                break;
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        EventBus.getDefault().register(this);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

        EventBus.getDefault().unregister(this);
    }
}
